var app = getApp();
var WxParse = require('../../../lib/wxParse/wxParse.js');
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');

Page({
  data: {
    id: 0,
    itemId: 0,
    receipt: {},
    imgs: []
  },
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    var that = this;

    that.setData({
      id: options.id,
      itemId: options.itemId
    });

    util.request(api.ReceiptDetail, {
      id: that.data.id,
      itemId: that.data.itemId
    }).then(function (res) {
      if (res.errno === 0) {
        // console.log(res.data)
        let receipt = res.data.purchase;
        receipt.remarkTime = util.formatTime2(new Date(receipt.remarkTime), "Y/M/D h:m:s");
        receipt.remarkImage && (receipt.remarkImage = receipt.remarkImage.split(',')[0]);
        receipt.remarkImage = receipt.remarkImage || '/static/images/receipt_item.png';
        that.setData({
          receipt: receipt
        });
      }
    });
  },
  preview(event) {
    let currentUrl = event.currentTarget.dataset.src
    wx.previewImage({
      current: currentUrl,
      urls: [currentUrl]
    })
  },
  onReady: function () {

  },
  onShow: function () {
    // 页面显示
  },
  onHide: function () {
    // 页面隐藏

  },
  onUnload: function () {
    // 页面关闭

  },
})